package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Pms_Category_Brand_Relation_Mapper;
import com.shop.mapper.Pms_Category_Mapper;
import com.shop.pojo.pms.Pms_Category_Brand_Relation;
import com.shop.service.Pms_Category_Brand_Relation_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Pms_Category_Brand_Relation_ServiceImpl implements Pms_Category_Brand_Relation_Service

{

    @Autowired
    private Pms_Category_Brand_Relation_Mapper pms_category_brand_relation_mapper;

    //注入分类的持久层
    @Autowired
    private Pms_Category_Mapper pms_category_mapper;

    /**
     * 维护品牌分类  进行的条件显示
     * @param page
     * @param pcbr
     * @return
     */
    @Override
    public LayuiUtils<Pms_Category_Brand_Relation> find_admin_category_brand_All(Page<Pms_Category_Brand_Relation> page, Pms_Category_Brand_Relation pcbr) {
        LayuiUtils<Pms_Category_Brand_Relation> lautis = new LayuiUtils<>();
        QueryWrapper<Pms_Category_Brand_Relation> Query = new QueryWrapper<>();
        //判断传来的值不为空在进行查询

            Query.eq("brand_id",pcbr.getBrand_id());
        if (!StringUtils.isEmpty(pcbr.getBrand_name())){
            //或者条件的多查询结果
            Query.like("brand_name",pcbr.getBrand_name())
                    .or().like("catelog_name",pcbr.getBrand_name());
        }
        Page<Pms_Category_Brand_Relation> cate_brand = pms_category_brand_relation_mapper.selectPage(page, Query);

        lautis.setCount(cate_brand.getTotal());
        lautis.setData(cate_brand.getRecords());

        return lautis;
    }


    /***
     * 添加分类品牌的信息进行维护
     * @param pcb
     * @return
     */
    @Override
    public R insert_admin_category_brand_All(Pms_Category_Brand_Relation pcb) {
        int inser = pms_category_brand_relation_mapper.insert(pcb);
        if(inser > 0){
            return R.success();
        }else{
            return R.error(500,"添加失败");
        }
    }

    /***
     * 删除分类品牌的信息
     * @param id
     * @return
     */
    @Override
    public R delete_admin_category_brand_All(List<Integer> id) {

        int i = pms_category_brand_relation_mapper.deleteBatchIds(id);
        if (i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /***
     * 修改分类品牌的信息
     * @param pmb
     * @return
     */
    @Override
    public R up_admin_category_brand_All(Pms_Category_Brand_Relation pmb) {
        int i = pms_category_brand_relation_mapper.updateById(pmb);
        if(i > 0 ){
            return R.success();
        }
        return R.error(500,"修改失败");
    }



}
